package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import world.CritterWorld;

public class FileBarPanel extends JPanel {
	
	private MainWindow mainFrame;
	private WorldViewPanel view;
	private CritterWorld world;
	
	private JButton loadWorldButton;
	private JButton addCritterButton;
	private JButton addPlantButton;
	private JButton addRockButton;
	private JButton editProgramButton;
	
	private final Color bkg = new Color(255,99,71);

	public FileBarPanel(CritterWorld w, MainWindow m, WorldViewPanel v, ActionListener playPause) {
		world = w;
		mainFrame = m;
		view = v;
		makeButtons(playPause);
		setBackground(bkg);
	}

	private void makeButtons(ActionListener playPause) {
		loadWorldButton = new JButton("Load World");
		addCritterButton = new JButton("Add Critter");
		addPlantButton = new JButton("Add Plant");
		addRockButton = new JButton("Add Rock");
		editProgramButton = new JButton("Edit selected critter's program");
		loadWorldButton.addActionListener(playPause);
		loadWorldButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				new LoadWorldFrame(mainFrame);
			}
		});
		addCritterButton.addActionListener(playPause);
		addCritterButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				new AddCritterFrame(world, view);
			}
		});
		addPlantButton.addActionListener(playPause);
		addPlantButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				world.getHex(view.getSelectedLoc()).putPlant();
				mainFrame.repaint();
			}
		});
		addRockButton.addActionListener(playPause);
		addRockButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				world.getHex(view.getSelectedLoc()).makeRock();
				mainFrame.repaint();
			}
		});
		editProgramButton.addActionListener(playPause);
		editProgramButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				if(view.getSelectedCritter() != null)
					new GenomeFrame(view.getSelectedCritter());
			}
		});
		add(loadWorldButton);
		add(addCritterButton);
		add(addPlantButton);
		add(addRockButton);
		add(editProgramButton);
	}
	
	public Dimension getMaximumSize(){
		return new Dimension(2000, 25);
	}
	
	public void changeWorld(CritterWorld w){
		world = w;
	}
	
	private class LoadWorldListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			
		}
	}
}
